using System.Windows;
using System.Windows.Controls;
using Common;

namespace ProjectView.ProjectControls
{
	internal class DataGridCellSelector : DataTemplateSelector
	{
		public DataTemplate Template { get; set; }

		public override DataTemplate SelectTemplate(object item, DependencyObject container)
		{
			FrameworkElement frameworkElement = container as FrameworkElement;
			DataGridCell dataGridCell = (container as ContentPresenter).Parent as DataGridCell;
			AQTargetDataRow aQTargetDataRow = dataGridCell.DataContext as AQTargetDataRow;
			if (aQTargetDataRow != null)
			{
				if (aQTargetDataRow.GetObject(dataGridCell.Column.DisplayIndex) is GridCheckBoxCell)
				{
					Template = frameworkElement.FindResource("CheckBoxDataTemplate" + dataGridCell.Column.DisplayIndex) as DataTemplate;
				}
				else if (aQTargetDataRow.ColumnItem.ToString() == Utility.GetMessage("Prj_Dye") || aQTargetDataRow.ColumnItem.ToString() == Utility.GetMessage("Prj_Excitation-Emission") || aQTargetDataRow.ColumnItem.ToString() == Utility.GetMessage("Prj_Select"))
				{
					Template = frameworkElement.FindResource("TextBlockDataTemplate" + dataGridCell.Column.DisplayIndex) as DataTemplate;
				}
				else
				{
					Template = frameworkElement.FindResource("TargetTextBlockDataTemplate" + dataGridCell.Column.DisplayIndex) as DataTemplate;
				}
			}
			return Template;
		}
	}
}
